<?php
$T->loadTpl("./html/".$template."/".$qname.".html");  
  
$access_token = isset($_COOKIE["w_tken"])?$_COOKIE["w_tken"]:"";
if(!empty($access_token)){
    $code=$_GET['code'];
    $s_url='https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token='.$access_token .'&code='.$code;
    $f_us = json_decode(file_get_contents($s_url));
    $uxid=$f_us->UserId;
    setcookie("wx_id",$uxid);

    $sql="select * from sys_member where qywxid='".$uxid."'";
    $ck_user=$T->db->query($sql)->fetch(PDO::FETCH_ASSOC);
    if($ck_user){
        if (!session_id()) session_start();
        $_SESSION["uid"]=$ck_user["id"];
        $_SESSION["username"]=$ck_user["username"];
        $_SESSION["idtype"]=$ck_user["idtype"];
        $_SESSION["department"]=$ck_user["department"];
        $_SESSION["role"]=$ck_user["role"];
        $_SESSION["school"]=$ck_user["school"];
        $_SESSION["nick"]=$ck_user["nick"];

        header("Location: ../?t=index" ); 
    }
}

$T->clearNaN();       
$T->clearNoN();
$T->display(); 